package com.adison.performancedemo.ui;

import com.adison.performancedemo.R;
import com.bumptech.glide.Glide;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by adison on 15/11/16.
 */
public class UIAdapter extends BaseAdapter {

    private Context mContext;

    public UIAdapter(Context context) {
        mContext=context;
    }

    @Override
    public int getCount() {
        return 1000;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view==null){
            viewHolder=new ViewHolder();
            view=View.inflate(mContext,R.layout.item_hierachy,null);
            viewHolder.nameTextView = (TextView) view.findViewById(R.id.item_name);
            viewHolder.imageView = (ImageView) view.findViewById(R.id.item_image);
            view.setTag(viewHolder);
        }else{
            viewHolder=(ViewHolder)view.getTag();
        }
        viewHolder.nameTextView.setText("测试[" + i + "]");
        Glide.with( mContext)
                .load(R.drawable.test_pic)
                .fitCenter()
                .into(viewHolder.imageView);
        viewHolder.imageView.setBackgroundColor(Color.TRANSPARENT);
        return view;
    }


    public static class ViewHolder {

        public TextView nameTextView;

        public ImageView imageView;

    }
}
